package com.winit.ogg.manager;

import com.winit.common.util.ShellRunUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by wangjian on 2017/10/25.
 */
@Component
public class PTServiceImpl implements OperateService {

    @Value("${shell_path}")
    private String SHELL_PATH;

    public Map<String, Object> start(String type) {
        if ("start_white".equals(type)) {
            return runOggCmd("sync_white_list");
        }
        return runOggCmd("start");
    }

    public Map<String, Object> status() {
        return runOggCmd("status");
    }

    public Map<String, Object> getLog() {
        return runOggCmd("getlog");
    }

    public Map<String, Object> check(String type) {
        if ("white".equals(type)) {
            return runOggCmd("check_white_list");
        }
        return runOggCmd("check");
    }

    //预算配置同步
    public Map<String, Object> budget() {
        return runOggCmd("sync_pms_budget");
    }

    private Map<String, Object> runOggCmd(String cmd) {
        return ShellRunUtil.runCmds("source /etc/profile && cd " + SHELL_PATH + " && bash c.sh " + cmd);
    }
}
